import ctypes
import unicodedata


# 计算字符宽度，中文算两个字符，英文算一个字符
def get_char_width(char):
    if unicodedata.east_asian_width(char) in ('F', 'W', 'A'):
        return 2
    return 1

# 计算字符串实际宽度
def get_str_width(s):
    return sum(get_char_width(c) for c in s)

def p(col1,col2,col3):
    # 启用 ANSI 转义序列支持
    kernel32 = ctypes.windll.kernel32
    mode = ctypes.c_ulong()
    handle = kernel32.GetStdHandle(-11)
    kernel32.GetConsoleMode(handle, ctypes.byref(mode))
    mode.value |= 0x0004
    kernel32.SetConsoleMode(handle, mode)

    # 定义颜色代码
    COLOR_HEADER = "\033[34m"  # 蓝色
    COLOR_DATA = "\033[32m"    # 绿色
    COLOR_RESET = "\033[0m"

    # 表头
    headers = [" 操 作","体力预计变化","启 用"]
    # 示例表格数据
    table_data = [headers] + list(zip(col1,col2,col3))

    # 计算每列的最大宽度
    column_widths = [max(get_str_width(str(row[i])) for row in table_data) for i in range(len(headers))]

    # 打印表格顶部边框
    top_border = "┌" + "┬".join("─" * (width + 2) for width in column_widths) + "┐"
    print(top_border)

    # 打印表格内容
    for i, row in enumerate(table_data):
        row_parts = []
        if i == 0:
            color = COLOR_HEADER
        else:
            color = COLOR_DATA
        for cell, width in zip(row, column_widths):
            cell_width = get_str_width(str(cell))
            padding = width - cell_width
            left_padding = padding // 2
            right_padding = padding - left_padding
            formatted_cell = color + " " * left_padding + str(cell) + " " * right_padding + COLOR_RESET
            row_parts.append(formatted_cell)
        row_content = "│ " + " │ ".join(row_parts) + " │"
        print(row_content)
        if i < len(table_data) - 1:
            mid_border = "├" + "┼".join("─" * (width + 2) for width in column_widths) + "┤"
            print(mid_border)

    # 打印表格底部边框
    bottom_border = "└" + "┴".join("─" * (width + 2) for width in column_widths) + "┘"
    print(bottom_border)